import { controller, httpGet as get, httpPost as post } from "inversify-express-utils";
import { PostServices } from "./post.services";
import { inject } from 'inversify'
import { Request, Response } from "express";

/**
 * ## Post 模块控制器
 * - 根路径：/post
 */

@controller('/post')
export class Post {

  constructor(
    @inject(PostServices) private readonly myPost: PostServices
  ) {}

  /**
   * ## 请求示例
   * - 请求方式：GET
   * - 请求路径：/post/get
   */
  @get('/get')
  public async get(req: Request, res: Response) {
    let result = this.myPost.get()
    res.cc('ok', {data: result}, 200)
  }

  /**
   * ## 请求示例
   * - 请求方式：POST
   * - 请求路径：/post/post
   */
  @post('/post')
  public async post(req: Request, res: Response) {
    let result = this.myPost.post(req.body)
    res.cc('ok', {data: result}, 200)
  }
}
